public class Solution1823 {
    public int findTheWinner(int n, int k) {
        int a=0;
        for (int i=2;i<=n;i++){
            a=(a+k)%i;
        }
        return a+1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1823().findTheWinner(5,2));
    }
}
